import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

let originPush = VueRouter.prototype.push;

VueRouter.prototype.push = function(location, resolve,reject){
	if(resolve && reject){
		originPush.call(this,location,resolve,reject)
	}else{
		originPush.call(this,location,()=>{},()=>{})
	}
}

import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'

export default new VueRouter({
	routes: [{
			path: '/home',
			component: Home,
			meta: {
				show: true
			}
		},
		{
			path: '/login',
			component: Login,
			meta: {
				show: false
			}
		},
		{
			path: '/register',
			component: Register,
			meta: {
				show: false
			}
		},
		{
			path: '/search/:keyWord?',
			component: Search,
			name: 'search',
			meta: {
				show: true
			},
			props: (route) => ({keyWord: route.params.keyWord,k: route.query.k})
		},
		{
			path: '/',
			redirect: '/home'
		}
	]
})